package com.ccjq.shosestore.web.controller.member;

import com.ccjq.shosestore.product.model.BrandModel;
import com.ccjq.shosestore.product.model.ProductModel;
import com.ccjq.shosestore.product.service.ProductService;
import com.ccjq.shosestore.product.service.impl.ProductServiceImpl;
import org.apache.commons.lang3.StringUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "HomeServlet")
public class HomeServlet extends HttpServlet {
    private static final String FALG_PRO = "index";//首页
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String flag = request.getParameter("flag");
        System.out.println("flag = " + flag);
        if (StringUtils.isBlank(flag)) {
            toProductPage(request,response);
        } else if (FALG_PRO.equals(flag)) {
            toProductPage(request,response);
        }
    }
    ProductService productService=new ProductServiceImpl();

    ProductService p = new ProductServiceImpl();
    private void toProductPage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        List<ProductModel> list= productService.getNewproductList();
        List<BrandModel> brand = p.getBrandTextList();
        List<ProductModel> hotlist = p.getFashionList();
        request.setAttribute("hot", hotlist);// 热卖
        request.setAttribute("list",list);
        request.getSession().setAttribute("brand", brand);
        request.getRequestDispatcher("/WEB-INF/jsp/home/firstPage.jsp").forward(request,response);
    }

}
